package com.reebake.ideal.security.authentication;

import com.reebake.ideal.servlet.util.WebUtil;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.logout.SimpleUrlLogoutSuccessHandler;

import java.io.IOException;

@RequiredArgsConstructor
public class SmartLogoutSuccessHandler extends SimpleUrlLogoutSuccessHandler {
	@Override
	public void onLogoutSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication)
			throws IOException, ServletException {
		if(WebUtil.isAjaxRequest(request)) {
			response.setStatus(HttpStatus.OK.value());
		}else {
			super.handle(request, response, authentication);
		}
	}
}
